// 集中管理异步请求，方便后期维护，提高可复用性
import request from "../utils/request";

// 获取banner
export const bannerGet = () => {
  return request.get("/classes/VueBanner");
};

// 更新banner
export const bannerPut = (id, bannerObj) => {
  return request.put(`/classes/VueBanner/${id}`, bannerObj);
};

// 商品批量转存
export const proBatch = (proList) => {
  let requests = proList.map((item) => {
    return {
      method: "POST",
      path: "/1.1/classes/VueProduct",
      body: item,
    };
  });
  return request.post("/batch", { requests });
};

// 商品列表 (前端筛选、排序)
export const proGet = (condition = {}) => {
  return request.get("/classes/VueProduct");
};

export const proGetBackend = (condition = {}, order = "-originprice") => {
  return request.get("/classes/VueProduct", {
    //get携带数据包必须包params
    params: {
      limit: 10,
      where: condition, //自定义条件
      order, // 排序条件
      // where: {
      //   category: "手机",
      // },
    },
  });
};

// 请求图表数据
export const chartGet = () => {
  return request.get("/classes/VueChart");
};
